package org.atlantis.juc.lock;

public class CLHLockUsage {

	private static Lock lock = new CLHLock();

	private static int count = 0;

	public static void main(String[] args) {
		for (int i = 0; i < 5; i++) {
			new Thread(new Task()).start();
		}
	}

	private static void inc() {
		lock.lock();
		count++;
		lock.unlock();
		System.out.println(count);
	}

	static class Task implements Runnable {

		@Override
		public void run() {
			try {
				Thread.sleep((long) (Math.random() * 1000));
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
			inc();
		}
	}
}
